package com.jinsi.service.lv.iml;



import com.jinsi.constant.LhrConstant;
import com.jinsi.mapper.lv.SyLvCourseClassificationMapper;
import com.jinsi.pojo.SyLvCoureseNode;
import com.jinsi.pojo.SyLvCourseClassification;

import com.jinsi.service.lv.SyLvCouresClassificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

@Service
public class SyLvCouresClassificationServiceImpI implements SyLvCouresClassificationService {
    @Autowired
    private SyLvCourseClassificationMapper syLvCourseClassificationMapper;
    @Transactional
    @Override
    public List<SyLvCourseClassification> getAllSort() {
        List<SyLvCourseClassification> getAllSort = syLvCourseClassificationMapper.getAllSort(null, LhrConstant.CUT_OFF);
        return  getAllSort;
    }
    @Transactional
    @Override
    public SyLvCourseClassification add(SyLvCourseClassification syLvCourseClassification) {
        syLvCourseClassificationMapper.add(syLvCourseClassification);
        return syLvCourseClassification;
    }
    @Transactional
    @Override
    public void updateu(SyLvCourseClassification syLvCourseClassification) {
        syLvCourseClassificationMapper.updateu(syLvCourseClassification);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void del(int classificationId) {
        syLvCourseClassificationMapper.del(classificationId,LhrConstant.DELETE);
    }

    /**
     * 获取课程下拉菜单数据
     * @param classificationPid
     * @return
     */
    @Transactional
    @Override
    public List<SyLvCoureseNode> getAllDropDownBox(Integer classificationPid) {
        List<SyLvCoureseNode> list = new ArrayList<>();
        List<SyLvCourseClassification> getAllSort = syLvCourseClassificationMapper.getAllSort(classificationPid,LhrConstant.CUT_OFF);
        for (SyLvCourseClassification a:getAllSort) {
            SyLvCoureseNode syLvCoureseNode = new SyLvCoureseNode();
            syLvCoureseNode.setId(a.getClassificationId());
            syLvCoureseNode.setTitle(a.getClassificationName());
            List<SyLvCoureseNode> getAllDropDownBox = getAllDropDownBox(a.getClassificationId());
            syLvCoureseNode.setChild(getAllDropDownBox);
            list.add(syLvCoureseNode);
        }
        return list;
    }
}
